﻿@model TestOnlineProject.Models.Entities.DiscussionCreateModel
@{
    ViewBag.Title = "Create";
}
<script type="text/javascript">
    tinymce.init({
        selector: "textarea",
        menubar: false,
        toolbar: "styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent",
        resize: false,
        statusbar: true,
        height: 300
    });

    $(document).ready(function() {
        // Show list question in modal
        $("#PopupQuestion").click(function() {
            $.ajax({
                url: "@Url.Content("~/Discussion/PopupQuestion")?subjectId=@ViewBag.Subject.SubjectId",
                success: function(data) {
                    $("#question").html(data);
                }
            });
        });

        // Add question to textare
        $('button[name=Add]').live("click", function() {
            var count = 0;
            var val = "";
            $(':checkbox:checked').each(function() {
                val += $(this).val() + "-";
                count++;
            });
            if (count == 0) {
                alert("Please select question");
            } else {
                var text = tinymce.activeEditor.getContent();
                $.ajax({
                    url: "@Url.Content("~/Discussion/AddQuestion")?ids=" + escape(val),
                    success: function(data) {
                        tinymce.activeEditor.setContent(text + data);
                        $('#question').modal('hide');
                    }
                });
            }
        });
    });
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { })
    / @Html.ActionLink("Subject Management", "Index", "Subject", new { }, null)
    / @Html.ActionLink((string)@ViewBag.Subject.Code, "Details", "Subject", new { id = @ViewBag.Subject.SubjectId }, null)
    / @Html.ActionLink("Discussions", "Index", "Discussion", new { subjectId = @ViewBag.Subject.SubjectId }, null)
    / Create Discussion
</div>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Discussion/Index")?subjectId=@ViewBag.Subject.SubjectId">
        <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
    </a></span>
</div>
<br />
@using (Html.BeginForm())
{
    @Html.HiddenFor(model => model.SubjectId)
    <fieldset>
        @if (ViewData.ModelState.Keys.Count > 3)
        {
            <div class="alert alert-error">
                @Html.ValidationSummary(true)
            </div>
        }
        <span>(*) is required</span>
        <table class="table table-bordered">
            <tr>
                <td style="width: 150px; text-align: right">
                    Title (*)
                </td>
                <td>
                    <span class="errorMsg">@Html.ValidationMessageFor(model => model.Title)</span>
                    @Html.TextBoxFor(model => model.Title, new {autocomplete = "off", placeholder = "Title"})
                </td>
            </tr>
            <tr>
                <td style="width: 150px; text-align: right">
                    Message (*)
                </td>
                <td>
                    
                    <div>
                        <span style="float: left" class="errorMsg">@Html.ValidationMessageFor(model => model.Content)</span>
                        <span style="float: right">
                            <a id="PopupQuestion" href="#question" role="link" class="btn btn-link" data-toggle="modal">
                                Add question</a>
                        </span>
                    </div>
                    <br />
                    <br />
                    <div>@Html.TextAreaFor(model => model.Content)</div>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <button id="create" type="submit" name="create" class="btn">
                        Create</button>
                    @Html.ActionLink("Reset", "Create", "Discussion", new {subjectId = @ViewBag.Subject.SubjectId}, new {@class = "btn", style = "width:54px"})
                    @Html.ActionLink("Cancel", "Index", "Discussion", new {subjectId = @ViewBag.Subject.SubjectId}, new {@class = "btn", style = "width:54px"})
                </td>
            </tr>
        </table>
    </fieldset>
}
<div id="question" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    @Html.Partial("_Question")
</div>
